package com.yidu.BusinessManagement.mapper;

import com.yidu.BusinessData.entity.Security;
import com.yidu.BusinessManagement.entity.DealData;
import com.yidu.BusinessParament.entity.Bond;
import com.yidu.BusinessParament.entity.Broker2;
import com.yidu.BusinessParament.entity.DealSeat;
import com.yidu.BusinessParament.entity.ExchangeRate;

import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author 苏彬
 * @date 2022/12/9 14:07
 **/
@Mapper
public interface DealDataMapper {
    @Select("SELECT dd.`commission` money, c.`accountName`,s.`securityName`,b.`brokerName`,dd.`seatName`,d.* FROM dealData d LEFT JOIN cash c ON d.`cashId`=c.`cashId` LEFT JOIN SECURITY s ON d.`securityId` = s.`securityId` LEFT JOIN broker b ON d.`brokerId`=b.`brokerId` left join dealSeat dd on d.`seatId`=dd.`seatId` WHERE 1=1 ${term} ORDER BY d.`dealTime` LIMIT #{page},#{row}")
    List<DealData> selectDealDate(Map map);

    @Select("select count(*) from dealData d left join SECURITY s ON d.`securityId`=s.`securityId` where 1=1 ${term}")
    int selectDealDateCount(Map map);

    @Delete("delete from dealData where dealId=#{dealId}")
    void deleteDealDate(String dealId);

    @Select("select * from SECURITY")
    List<Security> selectSecurity();

    @Select("select count(*) from SECURITY")
    int selectSecurityCount();

    @Select("SELECT e.`stampDuty`,e.`transferFee`,e.`collectionFee`,e.`handlingFee`,e.`exchangeType`,s.`securityType` FROM SECURITY s INNER JOIN exchangeRate e ON s.`securityType`=e.`exchangeType` AND s.`exchangeName`=e.`exchangeRateName` WHERE securityId=#{securityId}")
    ExchangeRate ExchangeRateMoney(String securityId);

    @Select("select * from broker")
    List<Broker2> selectBroker();

    @Select("select count(*) from broker")
    int selectBrokerCount();

    @Select("select * from dealSeat")
    List<DealSeat> selectDealSeat();

    @Select("select count(*) from dealData")
    int selectDealSeatCount();

    @Insert("INSERT INTO dealData VALUES(#{dealId},#{securityId},#{seatId},#{cashId},#{fundId},#{brokerId},#{dealTime},#{dealNumber},#{dealPrice},#{endTime},#{endMoney},#{dealMoney},#{commissionFees},#{transferFee},#{stampDuty},#{control},#{handle},#{securityInterest},#{dealWay},#{dealState},#{Remark});")
    int addDealDate(DealData data);

    @Update("update dealData set securityId=#{securityId},seatId=#{seatId},cashId=#{cashId},fundId=#{fundId},brokerId=#{brokerId},dealTime=#{dealTime},dealNumber=#{dealNumber},dealPrice=#{dealPrice},endTime=#{endTime},endMoney=#{endMoney},dealMoney=#{dealMoney},commissionFees=#{commissionFees},transferFee=#{transferFee},stampDuty=#{stampDuty},control=#{control},handle=#{handle},securityInterest=#{securityInterest},dealWay=#{dealWay},dealState=#{dealState},Remark=#{Remark} where dealId=#{dealId}")
    void updateDealDate(DealData data);

    @Select("select * from bond where bondId=#{securityId}")
    Bond selectBondd(String securityId);

    @Select("select commission from dealSeat where seatId=#{seatId}")
    String selectCommission(String seatId);
}
